package ca.ualberta.cs.BibTex;

public class Author {
	String abFirstMid;
	String first;
	String last;
	
	//to be extracted from the paper?
	String affiliation;
	String email;
	
	public Author(String abFM, String f, String l){
		abFirstMid = abFM;
		first = f;
		last = l;
	}

	@Override
	//a person may have several emails in different publications! But, also different people may have same names!
	//so, we take both, we only say two are for sure the same, if they have same names and same emails.
	public boolean equals(Object obj) {		
		if(! (obj instanceof Author) )
			return false;
		Author o = (Author) obj;
		if(last !=null && o.getLast() !=null && !last.equalsIgnoreCase(o.getLast()) )
			return false;
		if(abFirstMid != null && o.getAbFirstMid() !=null && !abFirstMid.equalsIgnoreCase(o.getAbFirstMid()) )
			return false;
		if(first !=null && o.getFirst() !=null && !first.equalsIgnoreCase(o.getFirst()) )
			return false;
		if(email != null && o.getEmail() != null && !email.equalsIgnoreCase(o.getEmail()))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		if( first != null)
			return first +" " +last ;
		else
			return abFirstMid +" " +last;
	}
	
	public String toStringForBib() {
		if( first != null)
			return last + ", " + first ;
		else
			return last +", " + abFirstMid;
	}
	
	
	public String getAbFirstMid() {
		return abFirstMid;
	}

	public void setAbFirstMid(String abFirstMid) {
		this.abFirstMid = abFirstMid;
	}

	public String getFirst() {
		return first;
	}

	public void setFirst(String first) {
		this.first = first;
	}

	public String getLast() {
		return last;
	}

	public void setLast(String last) {
		this.last = last;
	}

	public String getAffiliation() {
		return affiliation;
	}

	public void setAffiliation(String affiliation) {
		this.affiliation = affiliation;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	/*public Author parse(String nameString){
		return this;
	}*/
	
	
}
